package Utility.Utility;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class ChichoreSendMail {
	
	public static void main(String[] args) 
	{
		final String fromEmail = args[0];
		final String username = args[1];
		final String password = args[2];
		Properties properties = new Properties();
		properties.put("mail.smtp.auth", "true");
		properties.put("mail.smtp.starttls.enable", "true");
		properties.put("mail.smtp.host", "smtp.gmail.com");
		properties.put("mail.smtp.port", "587");
		
		Session session= Session.getInstance(properties, new Authenticator() 
			{
				protected PasswordAuthentication getPasswordAuthentication()
				{
					return new PasswordAuthentication(username, password);
				}
			});
		
		try
		{
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress(fromEmail));
			message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("abhijitbiet@gmail.com,sujoykumar.singha@gmail.com,sumit528.007@gmail.com,munna.biet@gmail.com,asu.ku.sahu@gmail.com"));
			message.setSubject("Testing JAVA MAIL");
			message.setText("Dear All Chichores,");
			message.setText("\n\n \t Please don't mark my email as spam!");
			message.setText("\n\n Regards");
			Transport.send(message);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}

}
